<?php

class Taichinh extends MY_Admin
{
	// Protected or private properties
	protected $_template;
	
	// Constructor
	public function __construct()
	{
		parent::__construct();

		// Check if the logged user is an administrator
		//$this->access_library->check_access();
		// Load needed models, libraries, helpers and language files
		$this->load->module_model('admin', 'taichinh_model', 'taichinh');
		$this->load->module_language('admin', 'general');
		$this->user = $this->access->get_user();
		$this->load->helper('url'); 
		$this->load->library('basic_library');
	}

	// Public methods
	public function chung_tu() 
	{
		//$this->access->restrict('Admin.Vattu.Index');
		
		$data['ItemID'] = 'User';
		$data['title'] = 'Danh sách Chứng từ tài chính';		
		
		$this->load->library('pagination');
		$this->load->helper('url');
		$config = array();
		$config['base_url'] 	= base_url().'admin/taichinh/chung_tu';
		$config['total_rows'] 	= $this->taichinh->count_all_chung_tu();
		$config['per_page'] 	= 100;
		$config['uri_segment']	= 4;
		$config['num_links'] = 5;
		$config['first_link'] = 'Đầu tiên';
        $config['last_link'] = 'Cuối cùng';
        $config['next_link'] = 'Tiếp theo';
        $config['prev_link'] = 'Lùi lại';
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(4))? $this->uri->segment(4):0;
		$data['sotrang']	=	$this->uri->segment(4);
		$data['listdata'] 	= $this->taichinh->get_all_chung_tu($config['per_page'], $page);
		$data['links'] 		= $this->pagination->create_links();		
		
		$this->_template['page']	= 'taichinh/chung_tu_list';
		$this->system_library->load($this->_template['page'], $data, TRUE);
	}
	
	public function hang_muc()
	{
		//$this->access->restrict('Admin.Vattu.Index');
	
		$data['ItemID'] = 'User';
		$data['title'] = 'Danh sách Hạng mục tài chính';
	
		$this->load->library('pagination');
		$this->load->helper('url');
		$config = array();
		$config['base_url'] 	= base_url().'admin/taichinh/hang_muc';
		$config['total_rows'] 	= $this->taichinh->count_all_hang_muc();
		$config['per_page'] 	= 100;
		$config['uri_segment']	= 4;
		$config['num_links'] = 5;
		$config['first_link'] = 'Đầu tiên';
		$config['last_link'] = 'Cuối cùng';
		$config['next_link'] = 'Tiếp theo';
		$config['prev_link'] = 'Lùi lại';
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(4))? $this->uri->segment(4):0;
		$data['sotrang']	=	$this->uri->segment(4);
		$data['listdata'] 	= $this->taichinh->get_all_hang_muc($config['per_page'], $page);
		$data['links'] 		= $this->pagination->create_links();
	
		$this->_template['page']	= 'taichinh/hang_muc';
		$this->system_library->load($this->_template['page'], $data, TRUE);
	}
	
	public function ton_dau_ky()
	{
		//$this->access->restrict('Admin.Vattu.Index');
	
		$data['ItemID'] = 'User';
		$data['title'] = 'Tồn đầu kỳ hạng mục tài chính';
	
		
		$data['listdata']	=	$this->taichinh->get_all_sddk();
	
		$this->_template['page']	= 'taichinh/ton_dau_ky';
		$this->system_library->load($this->_template['page'], $data, TRUE);
	}
	
// View Báo cáo tổng hợp
	public function report($duration=null)
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Báo cáo tổng hợp';
		$data['description'] = 'Báo cáo tổng hợp';
		$data['listdata']	=	$this->taichinh->get_report_tong_hop($duration);
		
		$data['listnguon'] =  $this->taichinh->get_report_tong_hop_nguon($duration);
		$this->_template['page']	= 'taichinh/report';
		$this->system_library->load($this->_template['page'], $data, TRUE);
	}
	
	public function enable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->hocvien->change_status_hocvien($id,1);
		redirect('admin/hocvien', 'refresh');
		
	}
	public function disable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->hocvien->change_status_hocvien($id,0);
		redirect('admin/hocvien', 'refresh');
	}
}

/* End of file jobs.php */